import { defineStore } from 'pinia';
import { ref } from 'vue';
// 引入获取试卷详情信息 的接口
import { getTestPaperDetail } from '@/api/assessment/testpapermanage.js'

export const useDictStore = defineStore('dictStore', () => {
  const singleChoiceIds = ref([])
  const multipleChoiceIds = ref([])
  const judgeChoiceIds = ref([])
  const fillChoiceIds = ref([])
  const discussChoiceIds = ref([])





  function addSingleChoiceId (id) {
    singleChoiceIds.value = id
  }

  function addMultipleChoiceId (id) {
    multipleChoiceIds.value = id
  }

  function addJudgeChoiceId (id) {
    judgeChoiceIds.value = id
  }

  function addFillChoiceId (id) {
    fillChoiceIds.value = id
  }

  function addDiscussChoiceId (id) {
    discussChoiceIds.value = id
  }

  function clearIds () {
    singleChoiceIds.value = []
    multipleChoiceIds.value = []
    judgeChoiceIds.value = []
    fillChoiceIds.value = []
    discussChoiceIds.value = []
  }

  function clearSingleChoiceId () {
    singleChoiceIds.value = []
  }

  function clearMultipleChoiceId () {
    multipleChoiceIds.value = []
  }

  function clearJudgeChoiceId () {
    judgeChoiceIds.value = []
  }

  function clearFillChoiceId () {
    fillChoiceIds.value = []
  }

  function clearDiscussChoiceId () {
    discussChoiceIds.value = []
  }

  const testpaperdetail = ref([]);

  async function getTestPaperDetailData (id) {
    const res = await getTestPaperDetail(id)
    testpaperdetail.value = res.data.topics
  }
  function editQuestion (id) {
    getTestPaperDetailData(id)
    const singleChoice = testpaperdetail.value.filter(item => item.topicType == 0)
    const multipleChoice = testpaperdetail.value.filter(item => item.topicType == 1)
    const judgeChoice = testpaperdetail.value.filter(item => item.topicType == 2)
    const fillChoice = testpaperdetail.value.filter(item => item.topicType == 3)
    const discussChoice = testpaperdetail.value.filter(item => item.topicType == 4)
    singleChoiceIds.value = singleChoice.map(item => item.id)
    multipleChoiceIds.value = multipleChoice.map(item => item.id)
    judgeChoiceIds.value = judgeChoice.map(item => item.id)
    fillChoiceIds.value = fillChoice.map(item => item.id)
    discussChoiceIds.value = discussChoice.map(item => item.id)
  }


  return {
    singleChoiceIds,
    multipleChoiceIds,
    judgeChoiceIds,
    fillChoiceIds,
    discussChoiceIds,
    addSingleChoiceId,
    addMultipleChoiceId,
    addJudgeChoiceId,
    addFillChoiceId,
    addDiscussChoiceId,
    clearIds,
    clearSingleChoiceId,
    clearMultipleChoiceId,
    clearJudgeChoiceId,
    clearFillChoiceId,
    clearDiscussChoiceId,
    editQuestion
  }
})